package com.jvtd.eyl.widget;

import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

import com.jvtd.eyl.R;
import com.jvtd.utils.UiUtils;
import com.jvtd.widget.banner.JvtdBanner;
import com.jvtd.widget.custom.JvtdCustomLinearLayout;
import com.youth.banner.listener.OnBannerListener;

import java.util.ArrayList;
import java.util.List;

/**
 * 精选 列表头部
 *
 * 作者:chenlei
 * 时间:2018/11/13 9:19 AM
 */
public class HomeHeaderView extends JvtdCustomLinearLayout {
    private JvtdBanner mBanner;

    public HomeHeaderView(Context context) {
        super(context);
    }

    public HomeHeaderView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public HomeHeaderView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public int getLayoutRes() {
        return R.layout.view_home_header;
    }

    @Override
    public void bindView(View view, @Nullable AttributeSet attrs) {
        mBanner = view.findViewById(R.id.banner);

        //设置banner的高度
        float ratio = 375.f / 165.f;
        UiUtils.setAutoHeight(mBanner, UiUtils.windowWidth(mContext), ratio);

        // 先为Banner设置一张默认图片
        List<String> imgList = new ArrayList<>();
        mBanner.setImages(imgList);
        // banner设置方法全部调用完毕时最后调用
        mBanner.start();
    }

    public void updateBanner(List<String> list) {
        mBanner.update(list);
    }

    public void start() {
        mBanner.startAutoPlay();
    }

    public void pause() {
        mBanner.stopAutoPlay();
    }

    public void setOnBannerListener(OnBannerListener onBannerListener) {
        mBanner.setOnBannerListener(onBannerListener);
    }
}
